package com.tuanzi.loan.web.bean.settlement;

import com.tuanzi.loan.business.entity.system.SystemUser;
import com.tuanzi.loan.business.service.settlement.CompanyInfoService;
import com.tuanzi.loan.business.service.system.SystemUserService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.settlement.CompanyInfoSearchRequest;
import com.tuanzi.loan.vo.response.settlement.CompanyInfoSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.settlement.CompanyInfoLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author caiwanlin
 * @create 2018-01-25 20:14
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class CompanyListBean  extends JSFListingSessionBean<CompanyInfoSearchRequest,CompanyInfoSearchResponse> {
    private Map<String,String> auditStatusMap;
    private List<SystemUser> principalList;
    @Autowired
    private SystemUserService systemUserService;
    @Autowired
    private CompanyInfoService companyInfoService;

    @Override
    protected String page() {
        return "/views/settlement/online-config/company-list.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new CompanyInfoSearchRequest();
        lazyDataModel = new CompanyInfoLazyDataModel($, session, companyInfoService);
        auditStatusMap = new HashMap<>();
        auditStatusMap.put("1","未提交");
        auditStatusMap.put("2","待核查");
        auditStatusMap.put("3","待审核");
        auditStatusMap.put("4","审核通过");
        auditStatusMap.put("5","审核不通过");
        principalList = systemUserService.findAll();
    }

    public void onReset(){
        initLazyDataModel();
    }

    public String onAdd(){
        return redirect("/views/settlement/online-config/info.xhtml");
    }
    public String onSee(Long id){
        return redirect("/views/settlement/online-config/info.xhtml?id="+id);
    }

    public String getAuditStatus(Integer auditStatus){
        return auditStatusMap.get(""+auditStatus);
    }
}
